import { BotLibrary, BotTags, Limits } from '@boticord/consts'
import {
  ArrayMaxSize,
  ArrayMinSize,
  IsArray, IsBoolean, IsIn, IsInt,
  IsOptional,
  IsString,
  IsUrl,
  Length,
  MaxLength,
  ValidateNested,
} from 'class-validator'
import { Type } from 'class-transformer'
import { PremiumBotDto } from './premium-bot.dto'
import { enumToValues, IsOptionalString } from '@boticord/common'

export class UpdateNotifySettingsDto {
  @IsOptional()
  @IsBoolean()
  declare enabled?: boolean
}

export class UpdateBotDto {
  @IsString()
  @Length(Limits.MinPrefixLength, Limits.MaxPrefixLength)
  declare prefix: string

  @IsString()
  @IsUrl({
    require_protocol: true,
    protocols: [ 'https' ],
  })
  @MaxLength(Limits.MaxBotInviteLinkLength)
  declare inviteLink: string

  @IsString()
  @Length(Limits.MinResourceDescriptionLength, Limits.MaxResourceDescriptionLength)
  declare description: string

  @IsString()
  @Length(Limits.MinResourceShortDescriptionLength, Limits.MaxResourceShortDescriptionLength)
  declare shortDescription: string

  @IsArray()
  @ArrayMaxSize(enumToValues(BotTags).length)
  @ArrayMinSize(Limits.MinTags)
  @IsIn(enumToValues(BotTags), { each: true })
  declare tags: number[]

  @IsArray()
  @ArrayMaxSize(Limits.MaxDevelopers)
  @ArrayMinSize(Limits.MinDevelopers)
  @IsString({ each: true })
  @Length(Limits.MinDiscordIdLength, Limits.MaxDiscordIdLength, { each: true })
  declare developers: string[]

  @IsOptionalString()
  @IsString()
  @Length(Limits.MinSupportServerInviteLength, Limits.MaxSupportServerInviteLength)
  declare supportServerInviteCode?: string

  @IsOptional()
  @IsInt()
  @IsIn(enumToValues(BotLibrary))
  declare library?: number

  @IsOptionalString()
  @IsString()
  @MaxLength(Limits.MaxSocialLinkLength)
  declare website?: string

  @IsOptionalString()
  @IsString()
  @Length(Limits.MinShortLinkLength, Limits.MaxShortLinkLength)
  declare shortLink?: string

  @IsOptional()
  @IsInt()
  declare standardBannerID?: number

  @IsOptional()
  @ValidateNested()
  @Type(() => PremiumBotDto)
  declare premium?: PremiumBotDto

  @IsOptional()
  @ValidateNested()
  @Type(() => UpdateNotifySettingsDto)
  declare notify?: UpdateNotifySettingsDto
}
